﻿Imports System.Collections.Generic
Partial Class Admin_KeywordsList
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        If Not Page.IsPostBack Then
            Dim l As ListItem = New ListItem
            l.Value = "-1"
            l.Text = ResourceManage.GetString("Select", "ru")
            l = New ListItem
            l.Value = "1"
            l.Text = ResourceManage.GetString("Add", "ru")
            l = New ListItem
            l.Value = "2"
            l.Text = ResourceManage.GetString("List", "ru")

            GridView1.Columns(0).HeaderText = ResourceManage.GetString("GridTitleDescription", "ru")
            GridView1.Columns(1).HeaderText = ResourceManage.GetString("GridTitleEdit", "ru")
            GridView1.Columns(2).HeaderText = ResourceManage.GetString("Delete", "ru")
            '       <asp:ListItem Selected="True" Value="-1">בחר טכנולוגיה</asp:ListItem>
            '<asp:ListItem Value="1" Text='<%#ResourceManage.GetString("PageKeywordList", "ru")%>'></asp:ListItem>
            '<asp:ListItem Value="2">רשימה</asp:ListItem>
        End If
    End Sub
    'Sub fillNavigationLinks()
    '    Dim navigation As System.Web.UI.HtmlControls.HtmlGenericControl = Master.FindControl("divNavigation")
    '    navigation.InnerHtml = "ðååè:  <a href=""main.aspx"">úôøéè øàùé</a> <img  src=""../images/arrow_p.gif"" /> <img  src=""../images/arrow_g.gif"" />  îàôééðéí  <img  src=""../images/arrow_gr.gif"" /> <img  src=""../images/arrow_pr.gif"" />"
    '    '  divItemNavigation.InnerHtml = "<img  src=""../images/arrow_p.gif"" /> <img  src=""../images/arrow_g.gif"" /> îåöøéí <img  src=""../images/arrow_gr.gif"" /> <img  src=""../images/arrow_pr.gif"" />"
    'End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            fillBlogList()
        End If

    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim IDI As Integer = CInt(GridView1.DataKeys(e.RowIndex).Values("KeyId"))
        Dim res As Boolean = KeyWords.Delete(IDI)
        If res = True Then
            Dim str As String = ResourceManage.GetString("Exception_KeywordOnDelete", "ru")
            ' divMsgText.InnerText = "רשומה מס " & IDI.ToString() & " נמחקה "
            GridView1.PageIndex = 0

            fillBlogList()
        Else
            Exit Sub
        End If


    End Sub

    Sub fillBlogList()
        'CType(IDP, DateTime)
        Dim arr As List(Of KeyItems) = KeyWords.KeyWordsget
        If Not arr Is Nothing Then

            GridView1.Visible = True
            GridView1.DataSource = arr
            GridView1.DataBind()
            'divMsg.Visible = False
            'divMsgText.Visible = False
            'divMsgText.InnerText = ""
        Else
            GridView1.Visible = False
        End If
    End Sub
    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        fillBlogList()
    End Sub
    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        fillBlogList()
    End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lnkDelete As Button = CType(e.Row.FindControl("lnkDelete"), Button)
            ' Dim str As String = 
            lnkDelete.Attributes.Add("onclick", "return confirm('" & ResourceManage.GetString("Exception_DeleteGridItem", "ru") & "');")
            '
        End If

    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim id As Integer = CInt(GridView1.DataKeys(e.RowIndex).Values("KeyId"))
        ' im()
        Dim txtOptionName As TextBox = CType(GridView1.Rows(e.RowIndex).FindControl("txtOptionName"), TextBox)
        If txtOptionName.Text.Trim = "" Then
            ' divMsgText.InnerText = "נא למלא שם הטכנולוגיה"
            Dim str As String = ResourceManage.GetString("Exception_KeywordOnInsert", "ru")
            Exit Sub
        End If

        Dim res As Integer = KeyWords.Update(id, txtOptionName.Text.Trim)
        If res > 0 Then
            Dim str As String = ResourceManage.GetString("Exception_KeywordOnUpdate", "ru")
            '"רשומה מס " & id.ToString() & " התעדכנה "
            GridView1.EditIndex = -1
            fillBlogList()
        End If

    End Sub
End Class
